package com.block.channel.service.monitor;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.block.channel.enums.MonitorChannelEnum;
import com.block.channel.model.dto.MonitorInfoDTO;
import com.block.channel.service.IChannelMonitorService;
import com.block.common.service.LogFactory;
import com.block.db.entity.ChannelBaseInfo;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * https://api.longzankeji.cn/apinotice/channel/notifyResult/rongyao/rongyao?actionType=CLICK&REQUESTID=__REQUESTID__&OS=__OS__&IP=__IP__&OAID=__OAID__&CREATIVEID=__CREATIVE_ID__&ADVERTISERID=__ADVERTISER_ID__&TRACKID=__TRACK_ID__&TIME=__TIME__&UA=__UA__
 * http://apitest.koukoudai.shop/apinotice/channel/notifyResult/rongyao/rongyao?&REQUESTID=__REQUESTID__&OS=__OS__&IP=__IP__&OAID=__OAID__&CREATIVEID=__CREATIVE_ID__&ADVERTISERID=__ADVERTISER_ID__&TRACKID=__TRACK_ID__&TIME=__TIME__&UA=__UA__
 */
@Service
public class RongYaoMonitorService implements IChannelMonitorService {

    private static Logger log = LogFactory.getCommLog();

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @Override
    public MonitorInfoDTO handleRequestParam(ChannelBaseInfo channelBaseInfo, String actionType, Map<String, String[]> parameterMap, String paramContent) {

        MonitorInfoDTO monitorInfoDTO = new MonitorInfoDTO();

        monitorInfoDTO.setPlatform(MonitorChannelEnum.RONGYAO.getValue());
        monitorInfoDTO.setChannelCode(channelBaseInfo.getChannelCode());
        monitorInfoDTO.setChannelName(channelBaseInfo.getChannelName());
        monitorInfoDTO.setMonitorInfo(JSON.toJSONString(parameterMap));

        String[] ADVERTISERID = parameterMap.get("ADVERTISERID");
        String[] OAID = parameterMap.get("OAID");
        String[] TRACKID = parameterMap.get("TRACKID");

        if (ObjectUtil.isNotEmpty(OAID)){
            monitorInfoDTO.setUniqueKey(OAID[0]);
            monitorInfoDTO.setKeyType("OAID");
        }

        if (ObjectUtil.isNotEmpty(ADVERTISERID)){
            monitorInfoDTO.setExtInfo(ADVERTISERID[0]);
        }
        if (ObjectUtil.isNotEmpty(TRACKID)){
            monitorInfoDTO.setCallbackInfo(TRACKID[0]);
        }

//        monitorInfoDTO.setCallbackInfo(JSON.toJSONString(callbackObject));

        monitorInfoDTO.setActionType(actionType);

        return monitorInfoDTO;
    }


}
